(function(self) {
	var url = app.server + "/signalr/hubs";
	
	console.log(url);
	
	self.connection = $.hubConnection(url);

	var connection = self.connection;
	//connection.logging = true;

	self.hub = connection.createHubProxy('TickerHub');

	var tryingToReconnect = false;

	connection.error(function(error) {
		console.log('SignalR error: ' + error);
		if(error == ("Error: Error during negotiation request.")){
			self.loginServer();
		}
	});
	
	connection.disconnected(function(error) {
		console.log('SignalR disconnected: ' + error);
	});

	connection.connectionSlow(function() {
		console.log("连接服务器的速度太慢.");
	});

	connection.reconnecting(function() {
		tryingToReconnect = true;
		console.log("连接服务器中...");
	}); 

	connection.reconnected(function() {
		tryingToReconnect = false;
		console.log("连接服务器成功.");
	});

	self.loginServer = function() {
		var account = app.account() || 'Signal'; 
		var loginInfo = {
			UserName: account,
			Password: 'Signal2016'
		};
		console.log(JSON.stringify(loginInfo));
		app.post("SignalRLogin", loginInfo, function(data) {
			console.log(JSON.stringify(data));
			init();
		});
	};
}(window.signalR = {}))